#!/usr/bin/env python
# -*- coding: utf-8 -*-

# created by: lavenliu
# created date: 2015-12-29

from socket import *
from time import ctime

HOST = ''
PORT = 21567
BUFSIZE = 1024
ADDR = (HOST, PORT)

tcpServSock = socket(AF_INET, SOCK_STREAM)
tcpServSock.bind(ADDR)
tcpServSock.listen(5)

while True:
    print "waiting for connection..."
    tcpCliSock, addr = tcpServSock.accept()
    print "...connected from:", addr

    while True:
        data = tcpCliSock.recv(BUFSIZE)
        if not data:
            break
        tcpCliSock.send('[%s] %s' % (ctime(), data))
    tcpCliSock.close()
tcpServSock.close()
